package com.yidu.qianfeng.common.util;

import java.util.Calendar;

/**
 * @Author: TangSheng
 * @Description: 主键生成工具类
 * @Date Created in 8:45 2021/3/31
 * @since 1.0
 */
public class PrimaryKeyUtil {


    /**
     * 生成唯一运单跟踪主键，未完成品，小型系统或可一用
     * @return 生成的主键
     */
    public static String generateTrackKey(String trackConsignNum){
        String year,month,dayOfMonth,hourOfDay,minute,second;

        Calendar now = Calendar.getInstance();

        year = Integer.toString(now.get(Calendar.YEAR));
        month = Integer.toString((now.get(Calendar.MONTH) + 1));
        dayOfMonth = Integer.toString(now.get(Calendar.DAY_OF_MONTH));
        hourOfDay = Integer.toString(now.get(Calendar.HOUR_OF_DAY));
        minute = Integer.toString(now.get(Calendar.MINUTE));
        second = Integer.toString(now.get(Calendar.SECOND));

        String trackKey = "T"+year+month+dayOfMonth+hourOfDay+minute+second+"w";
        if (trackConsignNum.length() > 4){
            trackKey += trackConsignNum.substring(0, 3);
            trackKey += trackConsignNum.charAt(trackConsignNum.length()-1);
        }else {
            trackKey += trackConsignNum;
        }
        trackKey += StrUtil.random_az();

        return trackKey;
    }







}
